#-------------------------------------------------------------------------------
# @file 	CMakeLists
# @author 	mojinpan
# @copyright (c) 2018-2024 mojinpan. All rights reserved.
# @brief 	linux下lib的CMake脚本
# @version 	V0.2
# @date 	2024-08-12
#
# @brief 	功能说明
# @details
# 1.按文件夹名称自动命名库文件
# 2.自动添加头文件给主cmake
# 3.自动将库信息添加到 STATIC_LIB_LIST 变量回传给主cmake
#
# @version 	V0.1
# @date 	2024-08-11
# @details
# 1.实现静态库编译
# 2.实现按文件夹命名库名称
# 3.实现头文件和库名称共享给主cmake
#
# @version 	V0.2
# @date 	2024-08-12
# @details
# 1.修正库名称无法传递给主cmake的bug
#
# @version 	V0.3
# @date 	2024-08-27
# @details
# 1.使用更通用的方式增加头文件
# 2.增加告警信息
#-------------------------------------------------------------------------------

# 获取当前目录的名称作为库名
get_filename_component(CMAKE_PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)

# 设置源文件变量
set(SRC "")

# 编译器配置
set (CMAKE_C_COMPILER   ${PREFIX}gcc)

# 设置编译器版本
set(CMAKE_C_STANDARD   99)

# 编译参数配置
list(APPEND CMAKE_C_FLAGS   "-Wall -Wno-psabi")

# 获取源文件
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRC)

# 添加静态库
add_library(${CMAKE_PROJECT_NAME} STATIC ${SRC})

# 将静态库添加到静态库列表(该列表由主CMake提供)
if(DEFINED STATIC_LIB_LIST)
    set(STATIC_LIB_LIST ${STATIC_LIB_LIST} ${CMAKE_PROJECT_NAME} PARENT_SCOPE)
else()
  message(FATAL_ERROR "The variable STATIC_LIB_LIST is not defined!")
endif()

# 共享头文件路径,用于主CMake编译
if(DEFINED LIB_INCLUDE_DIR_LIST)
    set(LIB_INCLUDE_DIR_LIST ${LIB_INCLUDE_DIR_LIST} ${CMAKE_CURRENT_SOURCE_DIR} PARENT_SCOPE)
else()
  message(FATAL_ERROR "The variable LIB_INCLUDE_DIR_LIST is not defined!")
endif()